package com.example.factory.core.domain;

import org.apache.commons.collections4.CollectionUtils;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

/**
 * @author Lei Tao
 */
@Entity
@Table(name = "report_plan")
public class ReportPlan extends DomainObject{
    /**
     * 评价人
     */
    @Column(name = "reporter_guid")
    private String reporterGuid;
    /**
     * 评价设备
     */
    @OneToMany(mappedBy = "reportPlan",fetch = FetchType.LAZY,orphanRemoval = true,cascade = {CascadeType.ALL})
    private List<ReportEquipment> reportEquipments;
    /**
     * 报告人
     */
    @Column(name = "grading_people_guid")
    private String gradingPeopleGuid;

    /**
     * 计划时间
     */
    @Column(name = "local_date")
    private LocalDate localDate;

    @OneToOne
    private ReportLevel1Dimension reportLevel1Dimension;

    @Enumerated(value = EnumType.STRING)
    @Column(name = "report_status")
    private ReportStatus reportStatus;

    @Column(name = "content")
    private String content;

    public ReportPlan() {
    }
    public void cascadeUpdateReportEquipments(List<ReportEquipment> reportEquipments) {
        if (CollectionUtils.isEmpty(this.reportEquipments)){
            this.reportEquipments = new ArrayList<>();
        }
        this.reportEquipments.clear();
        this.reportEquipments.addAll(reportEquipments);
    }

    public ReportLevel1Dimension getReportLevel1Dimension() {
        return reportLevel1Dimension;
    }

    public void setReportLevel1Dimension(ReportLevel1Dimension reportLevel1Dimension) {
        this.reportLevel1Dimension = reportLevel1Dimension;
    }

    public ReportStatus getReportStatus() {
        return reportStatus;
    }

    public void setReportStatus(ReportStatus reportStatus) {
        this.reportStatus = reportStatus;
    }

    public String getReporterGuid() {
        return reporterGuid;
    }

    public void setReporterGuid(String reporterGuid) {
        this.reporterGuid = reporterGuid;
    }

    public List<ReportEquipment> getReportEquipments() {
        return reportEquipments;
    }

    public void setReportEquipments(List<ReportEquipment> reportEquipments) {
        this.reportEquipments = reportEquipments;
    }

    public void addReportEquipments(ReportEquipment reportEquipment) {
        if (CollectionUtils.isEmpty(this.reportEquipments)){
            this.reportEquipments = new ArrayList<>();
        }
        this.reportEquipments.add(reportEquipment);
    }

    public String getGradingPeopleGuid() {
        return gradingPeopleGuid;
    }

    public void setGradingPeopleGuid(String gradingPeopleGuid) {
        this.gradingPeopleGuid = gradingPeopleGuid;
    }

    public LocalDate getLocalDate() {
        return localDate;
    }

    public void setLocalDate(LocalDate localDate) {
        this.localDate = localDate;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }
}
